package com.shuwen.gcdj.controller.basics;


import com.shuwen.gcdj.bean.SelectReq;
import com.shuwen.gcdj.bean.basicsRepair.request.*;
import com.shuwen.gcdj.bean.basicsRepair.response.*;
import com.shuwen.gcdj.bean.sysDictionary.request.SysDictionaryV1Req;
import com.shuwen.gcdj.bean.sysDictionary.response.SysDictionaryResp;
import com.shuwen.gcdj.common.annotation.JWTAuth;
import com.shuwen.gcdj.common.api.CommonPage;
import com.shuwen.gcdj.common.api.CommonResult;
import com.shuwen.gcdj.controller.AuthController;
import com.shuwen.gcdj.dto.account.InitUserDto;
import com.shuwen.gcdj.service.basics.RepairsService;
import com.shuwen.gcdj.service.sysDictionary.SysDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "报修管理")
@RestController
@RequestMapping
public class RepairsController extends AuthController {

    @Autowired
    private RepairsService repairsService;
    @Autowired
    private SysDictionaryService sysDictionaryService;

    @ApiOperation(value = "报修明细列表")
    @PostMapping("/repairaggregation/repairpagelist")
    @ResponseBody
    @JWTAuth
    public CommonResult<CommonPage<RepairListResp>> getList(@RequestBody RepairListReq req) {
        return repairsService.getList(req);
    }

    @ApiOperation(value = "新增报修")
    @PostMapping("/repairaggregation/addrepair")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> addRepairs(@RequestBody @Valid RepairAddReq req, HttpServletRequest request) {
        InitUserDto initUserDto = initUser(request);
        return repairsService.addRepairs(req, initUserDto);
    }

    @ApiOperation(value = "报修审核")
    @PostMapping("/repairaggregation/repaircheck")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> getAudit(@RequestBody @Valid RepairAuditReq req, HttpServletRequest request) {
        InitUserDto initUserDto = initUser(request);
        return repairsService.getAudit(req, initUserDto);
    }


    @ApiOperation(value = "报修验收")
    @PostMapping("/repairaggregation/getAcceptance")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> getAcceptance(@RequestBody @Valid RepairAuditReq req, HttpServletRequest request) {
        InitUserDto initUserDto = initUser(request);
        return repairsService.getAcceptance(req, initUserDto);
    }


    @ApiOperation(value = "报修派发")
    @PostMapping("/repairpersonnelassignmentaggregation/saverepairpersonnelassignment")
    @ResponseBody
    @JWTAuth
    public CommonResult<Integer> saveRepairPersonnelAssignment(@RequestBody @Valid RepairLinkReq req, HttpServletRequest request) {
        InitUserDto initUserDto = initUser(request);
        return repairsService.saveRepairPersonnelAssignment(req, initUserDto);
    }

    @ApiOperation(value = "报修处理")
    @PostMapping("/repairfeedbackaggregation/dispose")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> getDispose(@RequestBody RepairDetailResp req, HttpServletRequest request) {
        InitUserDto initUserDto = initUser(request);
        return repairsService.dispose(req, initUserDto);
    }


    @ApiOperation(value = "查看报修明细")
    @GetMapping("/repairaggregation/getrepair")
    @ResponseBody
    @JWTAuth
    public CommonResult<RepairDetailResp> getDetails(@RequestParam String id) {
        return repairsService.getRepair(id);
    }

    @ApiOperation(value = "查询部门人员")
    @GetMapping("/repairaggregation/getDepartmentUserTree")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DepartmentUserTreeResp>> getDepartmentUserTree(@RequestParam String orderCode) {
        return repairsService.getDepartmentUserTree(orderCode);
    }

    @ApiOperation(value = "报修明细-报修流程查看")
    @PostMapping("/repairflow/getflows")
    @ResponseBody
    public CommonResult<List<RepairPeopleReq>> getFlow(@RequestBody SelectReq req) {
        return repairsService.getFlow(req.getId());
    }

    @ApiOperation(value = "拖期配置-新增")
    @PostMapping("/orderdelayconfiguration/add")
    @ResponseBody
    @JWTAuth
    public CommonResult<RepaorResp> tardinessAdd(@RequestBody RepairTardinessReq req) {
        return repairsService.tardinessAdd(req);
    }

    @ApiOperation(value = "拖期配置-修改")
    @PostMapping("/orderdelayconfiguration/updatecycle")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> tardinessUpdate(@RequestBody RepairTardinessReq req) {
        return repairsService.tardinessUpdate(req);
    }

    @ApiOperation(value = "拖期配置-删除")
    @GetMapping("/orderdelayconfiguration/deleteasync")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> tardinessDelete(@RequestParam String id) {
        return repairsService.tardinessDelete(id);
    }

    @ApiOperation(value = "获取字典数据参数")
    @PostMapping("/basicssysdictionaryaggregation/getlistasync")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<SysDictionaryResp>> getListAsync(@RequestBody SysDictionaryV1Req req) {
        return CommonResult.success(sysDictionaryService.getChildByParentCode(req.getParentCode()));
    }

    @ApiOperation(value = "首页-报修统计")
    @GetMapping("/repairaggregation/getrepairstatekeyvalues/{equipmentId}")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<RepairIndexPageResp>> getRepairStateKeyValues(@PathVariable String equipmentId) {
        return CommonResult.success(repairsService.getRepairIndexPage(equipmentId));
    }

    @ApiOperation(value = "根据设备id获取策略信息")
    @GetMapping("strategyequipmentstrategyrel/getasync/{equipmentId}")
    @ResponseBody
    @JWTAuth
    public CommonResult<StrategyRelInfoResp> getStrategyByEquipmentId(@PathVariable String equipmentId) {
        return CommonResult.success(repairsService.getStategyIdByEquipmentId(equipmentId));
    }

    @ApiOperation(value = "获取拖期配置信息")
    @GetMapping("orderdelayconfigurationmanagement/getpage/{type}")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<OrderDelayconfigurationIResp>> getDelayList(@PathVariable Integer type) {
        return CommonResult.success(repairsService.getDelayList(type));
    }

    @ApiOperation(value = "首页工单预警统计")
    @GetMapping("/earlywarningstatistics/getequipmentstatestatistics/{equipmentcode}")
    @ResponseBody
    @JWTAuth
    public CommonResult<RepairEarlyWarningStatisticsResp> getRepairEarlyWringingStatistics(@PathVariable String equipmentcode) {
        return CommonResult.success(repairsService.getRepairEarlyWarningStatistics(equipmentcode));
    }


    @ApiOperation(value = "预警报修")
    @PostMapping("/repairaggregation/announciatorbyrepair")
    @ResponseBody

    public CommonResult<String> announciatorByRepair(@RequestBody AnnounciatorByRepairResp req) {
        return repairsService.announciatorByRepair(req);
    }

    @ApiOperation(value = "根据报修工单编号获取工单状态和流程信息")
    @GetMapping("/repairaggregation/getRepairStatusAndFlowDetailByRepairCode/{repairCode}")
    @ResponseBody
    public CommonResult<RepairProcessResults> getRepairStatusAndFlowDetailByRepairCode(@PathVariable String repairCode) {
        return repairsService.getRepairStatusAndFlowDetailByRepairCode(repairCode);
    }
}
